#!/bin/sh
#
# This is the script for generating files for a specific Dalton test job.
#
# For the .check file ksh or bash is preferred, otherwise use sh
# (and hope it is not the old Bourne shell, which will not work)
#
if [ -x /bin/ksh ]; then
   CHECK_SHELL='#!/bin/ksh'
elif [ -x /bin/bash ]; then
   CHECK_SHELL='#!/bin/bash'
else
   CHECK_SHELL='#!/bin/sh'
fi


#######################################################################
#  TEST DESCRIPTION
#######################################################################
cat > energy_solv.info <<'%EOF%'
   energy_solv
   -----------
   Molecule:         H2CO
   Wave Functions:   SCF, MP2 and MCSCF (CAS) / 6-31G
   Test Purpose:     Solvation energies; check .MOSTART H1DIAG option
%EOF%

#######################################################################
#  MOLECULE INPUT
#######################################################################
cat > energy_solv.mol <<'%EOF%'
BASIS
6-31G
Calculation of solvation energy

    3    2  X  Y        1.D-15
       8.     1    3    1    1    1
O1  0.000000  0.000000 -1.1466300
       6.     1    3    1    1    1
C2  0.000000  0.000000  1.1493700
        1.    1    2    1    1
H3  1.78680   0.000000  2.276770
%EOF%

#######################################################################
#  DALTON INPUT
#######################################################################
cat > energy_solv.dal <<'%EOF%'
**DALTON
.RUN WAVE FUCNTIONS
**INTEGRALS
.DIPLEN
.DIPVEL
*ONEINT
.SOLVENT
 7
**WAVE FUNCTIONS
.HF
.MP2
.MCSCF
*ORBITAL INPUT
.MOSTART   ! Huckel gives better start guess, but we must check somewhere
 H1DIAG    ! that the H1DIAG option works.
*SCF INP
.DOUBLY OCCUPIED
 5 1 2 0
*MP2 IN
.PRINT
  5
*CONFIG
.SYMMETRY
 1
.SPIN MUL
 1
.INACTIVE
 2 0 0 0
.ELECTRONS
 12
.CAS SPACE
 6 4 2 0
*SOLVENT
.CAVITY
 5.0
.INERSI initial state inertial polarization
  13.30D0    2.005D0
.MAX L
  7
.PRINT
  5
*OPTIMIZATION
.THRESHOLD
  1.D-06
.OPTIMAL ORBITAL TRIAL VECTORS
*CI VECTOR
.STARTHDIAG      | Compute start vector from Hessian CI-diagonal
**END OF DALTON INPUT
%EOF%
#######################################################################



#######################################################################

#######################################################################
#  CHECK SCRIPT
#######################################################################
echo $CHECK_SHELL >energy_solv.check
cat >>energy_solv.check <<'%EOF%'
log=$1

if [ `uname` = Linux ]; then
   GREP="egrep -a"
else
   GREP="egrep"
fi

# Integral setup
CRIT1=`$GREP "Calculation of one\- and two\-electron Hamiltonian integrals\." $log | wc -l`
CRIT1b=`$GREP "Calculation of one\-electron Hamiltonian integrals\." $log | wc -l`
CRIT2=`$GREP "The following one\-electron property integrals are calculated" $log | wc -l`
CRIT3=`$GREP "\- overlap integrals" $log | wc -l`
CRIT4=`$GREP "\- dipole length integrals" $log | wc -l`
CRIT5=`$GREP "\- dipole velocity integrals" $log | wc -l`
CRIT6=`$GREP "two-electron integrals are transformed to P-supermatrix elements" $log | wc -l`
CRIT6b=`$GREP "Fock matrices are calculated directly and in parallel without use of integrals on disk" $log |wc -l`
CRIT7=`$GREP "One\-electron RLM integrals calculated\." $log | wc -l`
CRIT8=`$GREP "Maximum L quantum number\: * 7" $log | wc -l`
CRIT9=`$GREP "All symmetries saved on file\." $log | wc -l`
TEST[1]=`expr	$CRIT1 \+ $CRIT2 \+ $CRIT3 \+ $CRIT4 \+ $CRIT5 \+ $CRIT6 \+ \
		$CRIT7 \+ $CRIT8 \+ $CRIT9 \+ $CRIT1b \+ $CRIT6b`
CTRL[1]=9
ERROR[1]="INTEGRAL CALCULATION NOT SET UP CORRECTLY"

# Basis set
CRIT1=`$GREP "Basis set used is \"6\-31G\" from the basis set library\." $log | wc -l`
CRIT2=`$GREP "O1 * 1 * 8\.0000 * 22 * 9 * \[10s4p\|3s2p\]" $log | wc -l`
CRIT3=`$GREP "C2 * 1 * 6\.0000 * 22 * 9 * \[10s4p\|3s2p\]" $log | wc -l`
CRIT4=`$GREP "H3 * 2 * 1\.0000 * 4 * 2 * \[4s\|2s\]" $log | wc -l`
CRIT5=`$GREP "total\: * 4 * 16\.0000 * 52 * 22" $log | wc -l`
TEST[2]=`expr	$CRIT1 \+ $CRIT2 \+ $CRIT3 \+ $CRIT4 \+ $CRIT5`
CTRL[2]=5
ERROR[2]="BASIS SET NOT READ CORRECTLY"

# Geometry
CRIT1=`$GREP "Total number of coordinates\: * 12" $log | wc -l`
CRIT2=`$GREP "1 * x * (0| )\.0000000000" $log | wc -l`
CRIT3=`$GREP "2 * y * (0| )\.0000000000" $log | wc -l`
CRIT4=`$GREP "3 * z * \-1\.1466300000" $log | wc -l`
CRIT5=`$GREP "4 * x * (0| )\.0000000000" $log | wc -l`
CRIT6=`$GREP "5 * y * (0| )\.0000000000" $log | wc -l`
CRIT7=`$GREP "6 * z * 1\.1493700000" $log | wc -l`
CRIT8=`$GREP "7 * x * 1\.7868000000" $log | wc -l`
CRIT9=`$GREP "8 * y * (0| )\.0000000000" $log | wc -l`
CRIT10=`$GREP "9 * z * 2\.2767700000" $log | wc -l`
CRIT11=`$GREP "10 * x * \-1\.7868000000" $log | wc -l`
CRIT12=`$GREP "11 * y * (0| )\.0000000000" $log | wc -l`
CRIT13=`$GREP "12 * z * 2\.2767700000" $log | wc -l`
TEST[3]=`expr	$CRIT1 \+ $CRIT2 \+ $CRIT3 \+ $CRIT4 \+ $CRIT5 \+ $CRIT6 \+ \
		$CRIT7 \+ $CRIT8 \+ $CRIT9 \+ $CRIT10 \+ $CRIT11 \+ $CRIT12 \+ \
		$CRIT13`
CTRL[3]=13
ERROR[3]="GEOMETRY NOT CORRECT"

# Symmetry
CRIT1=`$GREP "Number of coordinates in each symmetry\: * 4 * 4 * 3 * 1" $log | wc -l`
CRIT2=`$GREP "Number of orbitals in each symmetry\: * 12 * 6 * 4 * 0" $log | wc -l`
TEST[4]=`expr	$CRIT1 \+ $CRIT2`
CTRL[4]=2
ERROR[4]="SYMMETRY NOT CORRECT"

# Solvation model
CRIT1=`$GREP "SOLVATION MODEL\: molecule is in a spherical cavity in a dielectric medium\," $log | wc -l`
CRIT2=`$GREP "dielectric constant \= * 13\.300000" $log | wc -l`
CRIT3=`$GREP "cavity radius.* \= * 5\.000000" $log | wc -l`
CRIT4=`$GREP "max l value \= * 7" $log | wc -l`
TEST[5]=`expr	$CRIT1 \+ $CRIT2 \+ $CRIT3 \+ $CRIT4`
CTRL[5]=5
ERROR[5]="SOLVATION MODEL NOT CORRECT"

# Inertial polarization
CRIT1=`$GREP "This is the initial state in a calculation with inertial polarization\." $log | wc -l`
CRIT2=`$GREP "Converged T\(lm\) values are saved on the Sirius interface file\." $log | wc -l`
TEST[6]=`expr	$CRIT1 \+ $CRIT2`
CTRL[6]=2
ERROR[6]="INERTIAL POLARIZATION NOT REQUESTED"

# SCF energy
CRIT1=`$GREP "Hartree\-Fock total energy *\: * \-113\.416137335" $log | wc -l`
TEST[7]=`expr	$CRIT1`
CTRL[7]=1
ERROR[7]="SCF ENERGY NOT CORRECT"

# MP2 energy
CRIT1=`$GREP "\= MP2 second order energy *\: * \-113\.609683[4-5]" $log | wc -l`
TEST[8]=`expr	$CRIT1`
CTRL[8]=1
ERROR[8]="MP2 ENERGY  NOT CORRECT"

# MCSCF energy
CRIT1=`$GREP "Final MCSCF energy\: * \-114\.0030158235(0|1)[0-9]" $log | wc -l`
TEST[9]=`expr	$CRIT1`
CTRL[9]=1
ERROR[9]="MCSCF ENERGY NOT CORRECT"

PASSED=1
for i in 1 2 3 4 5 6 7 8 9
do
   if [ ${TEST[i]} -ne ${CTRL[i]} ]; then
     echo "${ERROR[i]} ( test = ${TEST[i]}; control = ${CTRL[i]} ); "
     PASSED=0
   fi
done

if [ $PASSED -eq 1 ]
then
  echo TEST ENDED PROPERLY
  exit 0
else
  echo THERE IS A PROBLEM
  exit 1
fi

%EOF%
#######################################################################
